/**
 * 
 */
jQuery(function($) {
		$.ajax({
			url : '/JFinalAdmin/admin/notify/info',
			type : 'GET',
			async : false,
			dataType : 'JSON',
			success : function(data){
				var taskNum = data.tasks,
					notificationNum = data.notifications,
					messageNum = data.messages,
					taskList = data.taskVos,
					notificationList = data.notificationVos,
					messageList = data.messageVos;
				
				renderTask(taskNum,taskList);
				renderNotification(notificationNum,notificationList);
				renderMessage(messageNum,messageList);
			}
		})
		
		function renderTask(taskNum,taskList){
			$('.grey').find('.task-num').text(taskNum);
			$('.grey').find('.task-info').text(' ' + taskNum + ' Tasks to complete');
			var taskContent = '';
			for(var i = 0 ; i < taskList.length; i++){
				var task = taskList[i],singleTask = '';
				singleTask = '<li><a href="#"><div class="clearfix">'
						   + '<span class="pull-left">' + task.description + '</span>'
						   + '<span class="pull-right">' + task.rate + '%</span>'
						   + '</div><div class="progress progress-mini">'
						   + '<div style="width:' + task.rate + '%" class="progress-bar"></div></div></a></li>';
				taskContent	+= singleTask;
			}
			$('.grey').find('.task-list').html(taskContent);
		};
		
		function renderNotification(notificationNum,notificationList){
			$('.purple').find('.notification-num').text(notificationNum);
			$('.purple').find('.notification-info').text(' ' + notificationNum + ' Notifications');
			var notificationContent = '';
			for(var i = 0 ; i < notificationList.length; i++){
				var notification = notificationList[i],singleNotification = '';
				singleNotification = '<li><a href="#"><div class="clearfix">'
								   + '<span class="pull-left"><i class="btn btn-xs no-hover btn-pink fa fa-comment"></i> '
								   + notification.description + '</span>'
								   + '<span class="pull-right badge badge-info">+' + notification.quantity + '</span>'
								   + '</div></a></li>';
				notificationContent	+= singleNotification;
			}
			$('.purple').find('.notification-list').html(notificationContent);
		}
		
		function renderMessage(messageNum,messageList){
			$('.green').find('.message-num').text(messageNum);
			$('.green').find('.message-info').text(' ' + messageNum + ' Messages');
			var messageContent = '';
			for(var i = 0 ; i < messageList.length; i++){
				var message = messageList[i],singleMessage = '';
				 singleMessage = '<li><a href="#">'
				 			   + '<img src="' + message.senderIcon + '" class="msg-photo" alt="' + message.senderName + '\'s Avatar" />'
							   + '<span class="msg-body"><span class="msg-title">'
						       + '<span class="blue">' + message.senderName + ' :</span> '
							   + message.content + '</span><span class="msg-time"><i class="ace-icon fa fa-clock-o"></i>'
						       + '<span> ' + message.recentTime + '</span></span></span>'
							   + '</a></li>';
						   messageContent	+= singleMessage;
			}
			$('.green').find('.message-list').html(messageContent);
			
		}
	})
	